package com.tony.study.annotation;

import java.lang.annotation.*;
import java.lang.reflect.Field;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: AnnotationTest01
 * @Auther: 皮蛋布丁
 * @Date: 2021/11/04/20:15
 * @Description:
 */
public class AnnotationTest01 {
    public static void main(String[] args) throws NoSuchFieldException {
        Class student = AnnotationStudent01.class;
        //通过反射获得注解
        Annotation[] annotations = student.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }

        //获取注解额value值
        AnnotationDemo02 annotationDemo02 = (AnnotationDemo02) student.getAnnotation(AnnotationDemo02.class);
        String value = annotationDemo02.value();
        System.out.println(value);

        //获取类指定的注解
        Field name = student.getDeclaredField("name");
        AnnotationDemo01 annotation = name.getAnnotation(AnnotationDemo01.class);
        System.out.println(annotation.value());
    }
}
